package ru.rchervot.sanasar.client.event;

import com.google.gwt.event.shared.GwtEvent;

public class EventRPCStatus extends GwtEvent<HandlerRPCStatus> {
	private static Type<HandlerRPCStatus> TYPE = new Type<HandlerRPCStatus>();
	
	public static enum Status {FAILURE, LOADING, SUCCESS};
	
	private final Status status;
	
	private EventRPCStatus() {
		status = null;
	} //TODO why not remove ?
	
	private EventRPCStatus(Status status) {
		this.status = status;
	}
	
	@Override
	protected void dispatch(HandlerRPCStatus handler) {
		handler.onStatusChange(this);
	}

	/**
	 * Gets the type associated with this event.
	 * 
	 * @return returns the handler type
	 */
	public static Type<HandlerRPCStatus> getType() {
		if (TYPE == null) {
			TYPE = new Type<HandlerRPCStatus>();
		}
		return TYPE;
	}

	@Override
	public Type<HandlerRPCStatus> getAssociatedType() {
		return TYPE;
	}

	public Status getStatus() {
		return status;
	}

	public static EventRPCStatus build(Status status) {
		return new EventRPCStatus(status);
	}

}
